<template>
  <div class="speedShare_wrap">
    <headTop :headClass="'white_header'">Sharing acceleration</headTop>
    <div class="scroll_wrap" ref="scrollBox">
      <div class="total_box">
        <h4>{{amount}}</h4>
        <span>Cumulative release</span>
      </div>
      <div class="kong"></div>
      <div class="list_wrap">
        <div class="tab_title">
          <div class="title_content" :class="`active${activeNum}`">
            <span class="detail">details</span>
          </div>
          <!-- Small calendar -->
          <div class="date_wrap" @click="goSelectStart">
            <span class="date">{{showDate}}</span>
            <span class="iconfont icon-rili"></span>
          </div>
        </div>
        <!-- Record list -->
        <ul class="detail_list" ref="scrollBoxInner">
          <li class="public_none_data" v-if="!list.length && isRequest">No data</li>
          <li class="detail_item" v-for="(item, index) in list" :key="index" v-else>
            <div class="left_box">
              <p class="nick">{{item.typeName}}</p>
              <span class="create_time">{{item.create_at}}</span>
            </div>
            <div class="right_box">
              <p class="num">{{item.money}}</p>
            </div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'speedShare',
  data () {
    return {
      amount: '',
      activeNum: Number(this.$route.query.num) || 0,
      isRequest: false, // Have you requested data?
      canRequest: true, // Can you request data, request lock?
      page: 1, // Paging default data
      hasMoreData: true, // Do you have more data?
      list: []
    };
  },
  methods: {
    // calendar event
    goSelectStart () {
      this.$store.commit('configDateWrap');
    },
    // Recording interface
    getInfo () {
      this.canRequest = false;
      this.axios.get('index/accountlog/release_record', {
        params: {
          page: this.page,
          time: this.startTime,
          type: 1
        }
      }).then(({data}) => {
        this.isRequest = true;
        if (data.code === 200) {
          this.amount = data.data.count;
          this.canRequest = true;
          this.page++;
          let resObj;
          resObj = data.data.list;
          if (resObj.length < 10 || !resObj.length || !resObj) {
            this.hasMoreData = false;
          } else {
            this.hasMoreData = true;
          }
          this.list = this.list.concat(resObj);
        } else {
          this.Toast(data.message);
        }
      });
    }
  },
  watch: {
    showDate () {
      this.page = 1;
      this.isRequest = false;
      this.list = [];
      this.getInfo();
    }
  },
  computed: {
    showDate () {
      if (!this.$store.state.date.selectResult[1]) {
        return 'This month';
      } else {
        return `${this.$store.state.date.selectResult[0]}-${this.$store.state.date.selectResult[1]}`;
      }
    },
    startTime () {
      if (!this.$store.state.date.selectResult[1]) {
        return `${new Date().getFullYear()}-${new Date().getMonth() + 1}`;
      } else {
        return this.$store.state.date.selectResult.join('-');
      }
    },
    endTime () {
      if (!this.$store.state.date.selectResult[1]) {
        return `${new Date().getFullYear()}-${new Date().getMonth() + 2}`;
      } else {
        return `${this.$store.state.date.selectResult[0]}-${this.$store.state.date.selectResult[1] + 1}`;
      }
    }
  },
  mounted () {
    this.$refs.scrollBox.onscroll = (e) => {
      let bottomClient = this.$refs.scrollBoxInner.clientHeight - e.target.scrollTop - e.target.clientHeight;
      if (bottomClient < 50 && this.canRequest && this.hasMoreData) this.getInfo();
    };
    this.getInfo();
  }
};
</script>

<style lang="scss" scoped>
  @import '../style/public.scss';
  .speedShare_wrap{
    height: 100%;
    padding-top: 90px;
    background: #fff;
    .scroll_wrap {
      height: 100%;
      overflow-y: scroll;
      .total_box {
        height: 203px;
        background: url('./../image/pic2_02.png') no-repeat;
        background-size: cover;
        padding-left: 45px;
        color: #fff;
        h4 {
          font-size: 48px;
          padding-top: 52px;
          font-weight: 500;
        }
        span {
          font-size: 24px;
        }
      }
      .kong {
        width: 100%;
        height: 20px;
        background: #f4f5f7;
      }
      .list_wrap {
        //  Record the head
        .tab_title {
          width: 100%;
          height: 95px;
          background: #fff;
          padding: 0 30px;
          display: flex;
          justify-content: space-between;
          align-items: center;
          border-bottom: 1Px solid #e6e6e6;
          .title_content{
            height: 100%;
            line-height: 95px;
            font-size: 28px;
            color: #666666;
          }
          .date_wrap{
            font-size: 24px;
            display: flex;
            align-items: center;
            .date{
              margin-right: 17px;
              color: #666;
            }
            .icon-rili{
              font-size: 30px;
              color: #2f2f2f;
            }
          }
        }
        // Record list
        .detail_list {
          padding: 0 30px;
          background: #fff;
          .detail_item {
            width: 100%;
            min-height: 142px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            border-bottom: 1Px solid #e6e6e6;
            .left_box {
              width: 80%;
              .nick {
                font-size: 28px;
                color: #222;
              }
              .create_time {
                font-size: 26px;
                color: #afafaf;
                padding-top: 10px;
              }
            }
            .right_box {
              .num {
                font-size: 30px;
                color: $color;
                text-align: right;
                margin-top: -40px;
              }
            }
          }
          // .detail_item:last-child {
          //   border-bottom: none;
          // }
          .public_none_data {
            position: absolute;
            left: 0;
            right: 0;
            top: 45%;
            bottom: 0;
            margin: auto;
          }
        }
      }
    }
  }
</style>
